package com.unifiedlibrary.amall_page.base.model;


import com.unifiedlibrary.amall_page.base.presenter.BasePresenter;

import io.reactivex.disposables.Disposable;

/**
 * @author xzk
 * @data 2019/2/26
 * @email xiezhengkun@beyondsoft.com
 * @remark 基类model，负责数据接收
 */
public class BaseModel<T extends BasePresenter> {
    protected T presenter;
    //rx的网络请求对象
    public Disposable disposable;

    public BaseModel() {
    }


    public void setPresenter(T presenter) {
        this.presenter = presenter;
    }

    /**
     * 回收保持的资源
     */
    public void recycleResource(){
        //回收网络请求（调用本方法表示，当前界面被干掉，那么网络请求也就不能再继续，避免内存泄漏发生）
        if (disposable != null && disposable.isDisposed()) {
            disposable.dispose();
        }
        if(presenter != null){
            presenter = null;
        }
    }


    /**
     * 数据获取监听
     * 成功
     * @param <T>
     */
    public interface OnObjectDataListener<T> {
        void onData(T data);
    }
    //失败
    public interface OnFailLinstener<T> {
        void onFail(T data);
    }
    //    错误异常
    public interface OnErrorLinstener<T> {
        void onError(T data);
    }

    public interface DownloadFileListener<P,F,E> {

        int download_error=-2;
        int download_progress=1;
        int download_complete=10000;

        void onStart();
        void onProgress(P p);
        void onFinish(F path);
        void onError(E msg);
    }


}
